﻿@model IEnumerable<Gateway.Console.Models.RoleModel>

@{
    ViewBag.Title = "Roles";
}

<h2>Roles</h2>
<hr />
<div class="panel panel-default">
    <div class="panel-heading">Application Role</div>
    <div class="panel-body">
        <form class="form-horizontal" role="form">
            <div class="form-group">
                @{var defaultRole = Model.FirstOrDefault(role => role.IsDefaultRole);}
                <label for="appRoleTargets" class="col-sm-1 control-label">Targets</label>
                <div class="col-sm-10">
                    <p class="form-control-static">
                        @foreach (var flight in defaultRole.Flights)
                        {
                            <div class="row">
                                <div class="col-sm-1">@flight.Weight</div>
                                <div class="col-sm-8">@flight.Redirect</div>
                            </div>
                        }
                    </p>
                </div>
            </div>
        </form>
    </div>
    <div class="panel-footer">@Html.ActionLink("Details", "Edit", new { id = defaultRole.Id })</div>
</div>

<div id="flightsRows" class="panel panel-default">
    <div class="panel-heading">Additional Roles</div>
    <table class="table table-hover">
        <thead>
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.RoleName)
                </th>
                <th>
                    Targets
                </th>
                <th></th>
            </tr>
        </thead>

        <tbody>
            @foreach (var item in Model.Where(role => !role.IsDefaultRole))
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.RoleName)
                    </td>
                    <td>
                        @foreach (var flight in item.Flights)
                        {
                            <div class="row">
                                <div class="col-sm-1">@flight.Weight</div>
                                <div class="col-sm-8">@flight.Redirect</div>
                            </div>
                        }
                    </td>
                    <td>
                        @Html.ActionLink("Details", "Edit", new { id = item.Id }) |
                        @Html.ActionLink("Delete", "Delete", new { id = item.Id })
                    </td>
                </tr>
            }
        </tbody>
    </table>
    <div class="panel-footer">@Html.ActionLink("Create New", "Create")</div>
</div>

